package com.newhope.srm.policy.service.report.conponent;

import com.newhope.srm.policy.entity.po.market.MarketIndexData;
import com.newhope.srm.policy.service.report.event.EventData;
import lombok.extern.slf4j.Slf4j;
import org.greenrobot.eventbus.EventBus;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class EventHandler {
    @Resource
    private EventBus eventBus;
    @Resource
    private EventDispatcher eventDispatcher;
    @PostConstruct
    public void init() {
        eventBus.register(eventDispatcher);
    }

    @PreDestroy
    public void destroy() {
        eventBus.unregister(eventDispatcher);
    }

    /**
     * 发送本地消息
     * @param eventData
     */
    public void postLocalEvent(List<MarketIndexData> eventData) {
        eventBus.post(eventData);
    }

    @Scheduled(fixedDelay = 100)
    public void loadMessages() {


    }
}